package com.joelapenna.foursquare.util;

import java.util.ArrayList;
import java.util.Arrays;

import com.joelapenna.foursquare.types.Badge;
import com.joelapenna.foursquare.types.Group;

public class BadgeUtils {
	
	private static ArrayList<String> defaultBadgeNames = new ArrayList<String>(Arrays.asList(
		"Newbie",
		"Adventurer",
		"Explorer",
		"Superstar",
		"Bender",
		"Crunked",
		"Local",
		"Super User",
		"Player Please!",
		"School Night",
		"Far Far Away",
		"Brooklyn 4 Life",
		"Photogenic",
		"Gossip Girl",
		"Socialite",
		"Douchebag",
		"Animal House",
		"Ziggy's Wagon",
		"Don't Stop Believin'",
		"Gym Rat",
		"Overshare",
		"Trainspotter",
		"JetSetter",
		"16 Candles",
		"Zoetrope",
		"Pizzaiolo",
		"Jobs",
		"Warhol",
		"Babysitter",
		"Swarm",
		"Super Mayor",
		"I'm on a boat!"
	));
	
	public static Group<Badge> getBadgeListWithDefaultBadges(Group<Badge> earnedBadges, String notEarnedDescription) {
		Group<Badge> badges = new Group<Badge>();
		earnedBadges = (Group<Badge>) earnedBadges.clone();
		
		for (String badgeName : defaultBadgeNames) {
			Badge badge = getEarnedBadgeFromList(earnedBadges, badgeName);
			
			if (badge==null) {
				badge = new Badge();
				badge.setName(badgeName);
				badge.setIcon("http://foursquare.com/img/badge/default_off.png");
				badge.setDescription(notEarnedDescription);
				
			}
			else
				earnedBadges.remove(badge);
			
			badges.add(badge);
		}
		
		// Non-default badges
		for (Badge badge : earnedBadges) {
			badges.add(badge);
		}
		
		return badges;
	}
	
	private static Badge getEarnedBadgeFromList(Group<Badge> earnedBadges, String badgeName) {
		for (Badge badge : earnedBadges) {
			if (badge.getName().equals(badgeName))
				return badge;
		}
		
		return null;
		
	}
}
